home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- //
- // Copyright (c) 2002, Colin Granville
- //
- // All rights reserved.
- //
- // Redistribution and use in source and binary forms, with or
- // without modification, are permitted provided that the following
- // conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- //
- // * Redistributions in binary form must reproduce the above
- // copyright notice, this list of conditions and the following
- // disclaimer in the documentation and/or other materials
- // provided with the distribution.
- //
- // * The name Colin Granville may not be used to endorse or promote
- // products derived from this software without specific prior
- // written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- // OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //--------------------------------------------------------------------------
-
- #include "GuiDrawFileSprite.h"
-
- GuiDrawFileSprite::GuiDrawFileSprite(GuiDrawFile& d)
- : drawfile(d)
- {
- }
-
- //***************************************************************
-
- GuiDrawFileSprite::~GuiDrawFileSprite()
- {
- }
-
- //***************************************************************
-
- void GuiDrawFileSprite::start(int width_pix,int height_pix,int bpp)
- {
- startPos=drawfile.startObject(sizeof(GuiDrawFileGraphicsObject) +
- sizeof(GuiTransform) +
- sizeof(GuiDrawFileSpriteBlock));
-
- if (drawfile.hasFailed()) return;
-
- sprite.offsetToMask=-1;
- int* p=(int*)sprite.name;
- p[0]= 's';p[1]=p[2]=0;
-
- if (bpp>16) {bpp=32;sprite.mode = (6<<27) | (90<<14) | (90<<1) | 1;}
- else if (bpp>8) {bpp=16;sprite.mode = (5<<27) | (90<<14) | (90<<1) | 1;}
- else if (bpp>4) {bpp=8; sprite.mode = 28;}
- else if (bpp>2) {bpp=4; sprite.mode = 27;}
- else if (bpp>1) {bpp=2; sprite.mode = 26;}
- else {bpp=1; sprite.mode = 25;}
-
- sprite.leftHandWastage = 0;
- sprite.height = height_pix-1;
- int bits=width_pix*bpp-1;
- sprite.width = bits/32;
- sprite.lastBitUsed = bits & 31;
-
- if (height_pix*width_pix > (1024*512))
- {
- int spriteSize=(bits/8)*height_pix;
-
- if (sprite.mode>>27)
- {
- int bits=(sprite.width*32) + sprite.lastBitUsed;
- int pix=((bits+1) >> ((sprite.mode >> 27)-1));
- spriteSize += (4*(pix + 31)/32);
- }
- else
- spriteSize*=2;
- drawfile.ensureMem(spriteSize+(1024*4));
- }
- }
-
- //***************************************************************
-
- void GuiDrawFileSprite::startImage()
- {
- sprite.offsetToImage = drawfile.getSize() -
- startPos -
- sizeof(GuiDrawFileGraphicsObject) -
- sizeof(GuiTransform);
- if (sprite.offsetToMask==-1) sprite.offsetToMask = sprite.offsetToImage;
- }
-
- //***************************************************************
-
- void GuiDrawFileSprite::startMask()
- {
- sprite.offsetToMask = drawfile.getSize() -
- startPos -
- sizeof(GuiDrawFileGraphicsObject) -
- sizeof(GuiTransform);
- }
-
- //***************************************************************
-
- void GuiDrawFileSprite::startMaskFill()
- {
- unsigned int words = sprite.width+1;
- if (sprite.mode>>27)
- {
- int bits=(sprite.width*32) + sprite.lastBitUsed;
- int pix=((bits+1) >> ((sprite.mode >> 27)-1));
- words = (pix + 31)/32;
- }
- words*= (sprite.height+1);
- startMask();
- for (;words;words--) put(0u);
- }
-
- //***************************************************************
-
- void GuiDrawFileSprite::end(const GuiTransform& transform, const GuiBBox& bounds)
- {
- if (drawfile.hasFailed()) return;
-
- GuiDrawFileGraphicsObject& object = *(GuiDrawFileGraphicsObject*)drawfile.getPtr(startPos);
- object.typeId = OBJECT_ID;
- object.size = drawfile.getSize() - startPos;
- object.bounds = bounds;
-
- *(GuiTransform*) ( (char*)(&object+1) ) = transform;
-
- sprite.size=object.size - sizeof(GuiDrawFileGraphicsObject) - sizeof(GuiTransform);
-
- *(GuiDrawFileSpriteBlock*)( (char*)(&object+1) + sizeof(GuiTransform) ) = sprite;
- drawfile.addBBox(bounds);
- drawfile.endObject();
- }
-